package com.qfedu.edu.finishorderservice.queue.receive;

import com.qfedu.edu.finishorderservice.service.OrderService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * @author xiaobobo
 * @title: orderStatusCheckQueueListener
 * @projectName seckill-fy-2401-parent
 * @description: 订单状态检测的这个TTL队列
 * @date 2024/11/14  16:50
 */
@Component
public class orderStatusCheckQueueListener {

    @Autowired
    private OrderService orderService;

    @RabbitListener(queues = {"orderTTLQueue"})
    public void receive(byte[] data, Message message, Channel channel) throws IOException {
        String val = new String(data, "UTF-8");
        //接下来：就可以调用业务逻辑了
        orderService.orderStatusCheck(val);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),true);
    }

}
